from PyQt4 import QtCore, QtGui;

class EdgeCtrlPoint(QtGui.QGraphicsObject):
    def __init__(self, parent=None, qPos=None, bRemovable=False):
        super(EdgeCtrlPoint, self).__init__(parent);
        self.setFlag(QtGui.QGraphicsItem.ItemIsMovable, True);
        self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable, True);
        self.setPos(qPos);
        self.oldPosInc = self.pos();
        self.oldPos, self.newPos = self.pos(), self.pos();
        self.bRemovable = bRemovable;
        self.bItemMoved = False;
        self.setVisible(False);
        self.createCtrlPoint();        
        
    def createCtrlPoint(self):
        self.qPath = QtGui.QPainterPath();
        nS = 8;
        self.qPath.addEllipse(-nS/2, -nS/2, nS, nS);

    def shape(self):
        return self.qPath;
    
    def boundingRect(self):
        return self.qPath.boundingRect();
    
    def checkItemMove(self):
        if (self.oldPosInc != self.pos()):
            self.bItemMoved = True;
            self.oldPosInc = self.pos();
        
    def paint(self, painter, option, widget):
        self.prepareGeometryChange();
        self.checkItemMove();
        if self.isSelected():
            painter.setPen(QtGui.QPen(QtCore.Qt.blue, 1.5));
        else:
            painter.setPen(QtGui.QPen(QtCore.Qt.red, 0.5));            
        painter.setBrush(QtGui.QBrush(QtCore.Qt.yellow));
        painter.drawEllipse(self.qPath.boundingRect());

    def setCtrlPointStyle(self, nStyle):
        pass;
    
    def setCtrlPointOption(self, nOpt, value):
        pass;
